package com.kang.service.serviceImpl;

import com.kang.mapper.CatalogMapper;
import com.kang.mapper.ItemsMapper;
import com.kang.pojo.Catalog;
import com.kang.pojo.Items;
import com.kang.service.CatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 吃三明治派对中的康康
 * @Date 2022/4/25 20:06
 * @Version 1.0
 */

@Service
public class CatalogServiceImpl implements CatalogService {

    @Autowired
    CatalogMapper catalogMapper;
    @Autowired
    ItemsMapper itemsMapper;


    public List<Catalog> allCatalog() {
        return catalogMapper.selectAllCatalog();
    }

    public List<Items> oneOfItems(){

        ArrayList<Items> itemsArrayList = new ArrayList<>();
        List<Catalog> catalogs = allCatalog();
        for (Catalog catalog : catalogs) {
            //如果查询不为空
            if(itemsMapper.searchOneByCatalog(catalog.getCatalog()) != null){
                itemsArrayList.add(itemsMapper.searchOneByCatalog(catalog.getCatalog()));
            }
        }

        return itemsArrayList;
    }

    @Override
    public String nullCatalogString() {

        StringBuilder nullSting = new StringBuilder();

        List<Catalog> catalogs = allCatalog();
        for (Catalog catalog : catalogs) {
            //如果查询不为空
            if(itemsMapper.searchOneByCatalog(catalog.getCatalog()) == null){
                nullSting.append(catalog.getCatalog());
            }
        }
        return nullSting.toString();
    }
}
